home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / processes / procdoggie / uprocessldef.p < prev    next >
Encoding:
Text File  |  2000-09-28  |  7.5 KB  |  228 lines

  1. {
  2.     File:        UProcessLDEF.p
  3.  
  4.     Contains:    This LDEF is a simple replacement for the standard LDEF.  The only advantange
  5.                 this LDEF has over the standard LDEF is that it contains information specific
  6.                 to processes that aren’t displayed.  This is to make identifying processes in
  7.                 the Process List window easier.
  8.     
  9.                 Once the icon utilities are released to the developer community, this LDEF
  10.                 will be updated to display the icon of each process in the list.
  11.  
  12.     Written by: Forrest Tanaka    
  13.  
  14.     Copyright:    Copyright © 1988-1999 by Apple Computer, Inc., All Rights Reserved.
  15.  
  16.                 You may incorporate this Apple sample source code into your program(s) without
  17.                 restriction. This Apple sample source code has been provided "AS IS" and the
  18.                 responsibility for its operation is yours. You are not permitted to redistribute
  19.                 this Apple sample source code as "Apple sample source code" after having made
  20.                 changes. If you're going to re-distribute the source, we require that you make
  21.                 it clear in the source that the code was descended from Apple sample source
  22.                 code, but that you've made changes.
  23.  
  24.     Change History (most recent first):
  25.                 7/27/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  26.                 
  27.  
  28. }
  29. UNIT UProcessLDEF;
  30. {[j=20/57/1$] Pasmat Options}
  31.  
  32.  
  33. INTERFACE
  34.  
  35.  
  36. (*******************************************************************************
  37. * Used Units
  38. *******************************************************************************)
  39.  
  40.     USES
  41.         Processes
  42.         ,Lists
  43.         ;
  44.  
  45. (*******************************************************************************
  46. * Types
  47. *******************************************************************************)
  48.  
  49.     TYPE
  50.         ProcessListInfoRec = RECORD
  51.             processName:    Str255;               {Process’s name}
  52.             serialNumber:   ProcessSerialNumber  {Process’s serial number}
  53.         END;
  54.         ProcessListInfoPtr = ^ProcessListInfoRec;
  55.  
  56.  
  57. (*******************************************************************************
  58. * ProcessList - Entry point to the List Definition Procedure
  59. *
  60. * This is the entry point to the custom list defproc used in ProcDoggie.  ProcDoggie
  61. * actually uses the world's simplest LDEF.  All that LDEF does is call through
  62. * the ListRec's refCon field.  So we jam the address of ProcessListLDEF into that
  63. * field and, voila, we don't have to have a separate LDEF and we can debug
  64. * our LDEF in a high-level debugger.  It's kinda like the classic "6 byte LDEF"
  65. * trick, except we don't have to worry about cache flushing.
  66. *******************************************************************************)
  67.  
  68.     PROCEDURE ProcessListLDEF (message:    Integer;
  69.                            selectCell: Boolean;
  70.                            VAR cellRect:   Rect;
  71.                            theCell:    Cell;
  72.                            dataOffset: Integer;
  73.                            dataLength: Integer;
  74.                            theList:    ListHandle);
  75.  
  76.  
  77. IMPLEMENTATION
  78.  
  79.     USES
  80.         Script
  81.         ,TextEdit
  82.         ,LowMem
  83.         ,ToolUtils
  84.         ;
  85.  
  86.     CONST
  87.         kCellMargin = 3; {Margin between list contents and list edge in pixels}
  88.  
  89.  
  90.     {$S Main}
  91.     (*******************************************************************************
  92.     * Private: HilightCell - Hilight the specified cell
  93.     *
  94.     * This routine hilights the cell whose rectangle is cellRect.  I also clear the
  95.     * hilight bit of the HiliteMode low-memory global.  If this is running on a
  96.     * Color QuickDraw machine, then background hilighting is done instead of
  97.     * the usual inversion.
  98.     *******************************************************************************)
  99.  
  100.     PROCEDURE HilightCell (cellRect: Rect);
  101.  
  102.     VAR
  103.         hiliteModeValue:    ByteParameter;
  104.         
  105.     BEGIN
  106.         (* Do the fancy, new kind of hilighting on a Color QuickDraw Mac *)
  107.         hiliteModeValue := LMGetHiliteMode;
  108.         BitClr(Ptr(@hiliteModeValue), pHiliteBit);
  109.         LMSetHiliteMode(hiliteModeValue);
  110.  
  111.         (* Now, hilight the cell *)
  112.         InvertRect (cellRect)
  113.     END;
  114.  
  115.  
  116.     {$S Main}
  117.     (*******************************************************************************
  118.     * Private: DrawCell - Draw the contents of the specified cell
  119.     *
  120.     * This routine draws the contents of the cell specified by theCell into it’s
  121.     * rectangle, which is specified by cellRect.  In case the font is too large for
  122.     * the cell rectangle, I set the clip region to cellRect before drawing the cell
  123.     * text, then set it back to what it was afterwards.
  124.     *
  125.     * If selected is TRUE, then theCell is selected.  In that case, my HilightCell
  126.     * routine is called to hilight the cell.
  127.     *
  128.     * The list that this all takes place in is specified by theList.
  129.     *******************************************************************************)
  130.  
  131.     PROCEDURE DrawCell (cellRect:   Rect;
  132.                         theCell:    Cell;
  133.                         selected:   Boolean;
  134.                         theList:    ListHandle;
  135.                         dataOffset: Integer);
  136.  
  137.         VAR
  138.             cellInfo:   ProcessListInfoRec; {Information for cell to be drawn}
  139.             currClip:   RgnHandle;          {Handle to the current clip region}
  140.             currPen:    PenState;           {Current pen characteristics}
  141.             currFont:   FontInfo;           {Current font characteristics}
  142.             dataLen:    Integer;            {Length of cell data in bytes}
  143.             marginRect: Rect;               {Rect that process name is drawn into}
  144.             alignment:  Integer;            {Alignment of process name text}
  145.             spareSpace: Integer;            {marginRect width - text width}
  146.  
  147.     BEGIN
  148.         {$unused dataOffset}
  149.         
  150.         (* Save the current pen state and set the default pen characteristics *)
  151.         GetPenState ((*<*)currPen);
  152.         PenNormal;
  153.  
  154.         (* Save the current clip region and set it to cellRect *)
  155.         currClip := NewRgn;
  156.         GetClip ((*<*)currClip);
  157.         ClipRect (cellRect);
  158.  
  159.         (* Will draw text into the cell rect with a margin on left and right *)
  160.         marginRect := cellRect;
  161.         InsetRect ((*◊*)marginRect, kCellMargin, 0);
  162.  
  163.         (* Get the information for the specified cell *)
  164.         dataLen := SIZEOF (ProcessListInfoRec);
  165.         LGetCell ((*<*)Ptr(@cellInfo), (*◊*)dataLen, theCell, theList);
  166.  
  167.         (* To find where to draw the cell’s text, get current font information *)
  168.         GetFontInfo ((*<*)currFont);
  169.  
  170.         (* Position the pen for drawing the text *)
  171.         MoveTo (marginRect.left, marginRect.top + currFont.ascent);
  172.  
  173.         (* Determine whether system script is left-to-right or right-to-left *)
  174.         IF GetSysDirection = 0 THEN
  175.             alignment := teFlushLeft
  176.         ELSE
  177.             alignment := teFlushRight;
  178.  
  179.         (* Adjust the pen for right-aligned text if script is right-to-left *)
  180.         IF alignment = teFlushRight THEN
  181.             BEGIN
  182.                 spareSpace := marginRect.right - marginRect.left -
  183.                         StringWidth (cellInfo.processName);
  184.                 Move (spareSpace, 0);
  185.             END;
  186.  
  187.         (* Draw the cell’s contents *)
  188.         EraseRect (cellRect);
  189.         DrawString (cellInfo.processName);
  190.  
  191.         (* If the cell is selected, hilight it *)
  192.         IF selected THEN
  193.             HilightCell (cellRect);
  194.  
  195.         (* Restore the current clip region and pen *)
  196.         SetClip (currClip);
  197.         DisposeRgn (currClip);
  198.         SetPenState (currPen);
  199.     END;
  200.  
  201.  
  202.     {$S Main}
  203.     (*******************************************************************************
  204.     * Public: ProcessList
  205.     *
  206.     * Here’s the entry point to my custom LDEF.  Yup.
  207.     *******************************************************************************)
  208.  
  209.     PROCEDURE ProcessListLDEF (message:    Integer;
  210.                            selectCell: Boolean;
  211.                            VAR cellRect:   Rect;
  212.                            theCell:    Cell;
  213.                            dataOffset: Integer;
  214.                            dataLength: Integer;
  215.                            theList:    ListHandle);
  216.  
  217.     BEGIN
  218.         IF message = lDrawMsg THEN
  219.             BEGIN
  220.                 IF dataLength > 0 THEN
  221.                     DrawCell (cellRect, theCell, selectCell, theList, dataOffset)
  222.             END
  223.         ELSE IF message = lHiliteMsg THEN
  224.             HilightCell (cellRect)
  225.     END;
  226.  
  227. END.
  228.